<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="itheima" uri="http://systop.com/common/"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script
	src="${pageContext.request.contextPath }/js/jquery-1.11.3.min.js"
	charset="utf-8"></script>
<!--[if lt IE 9]>
    <script src="http://cdn.static.runoob.com/libs/html5shiv/3.7/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/bootstrap.min.css">
<style>
#back {
	background-image:
		url(${pageContext.request.contextPath }/images/sun.png);
	background-size: 100%;
	background-repeat: no-repeat;
}

#body {
	background: #f2f2f2;
	width: 1000px;
	margin: 0 auto;
	height: 100%;
	border-radius: 10px;
}

.table>thead>tr>th {
	text-align: center;
}

.order {
	float: right;
}

.fixed-bottom {
	position: fixed;
	bottom: 0;
	width: 100%;
}

.form-group {
	margin-left: 170px
}
</style>
<script type="text/javascript">
function sendNewMess() {
	var titleName = $("#titleName").val();
	var titleInfo = $("#titleInfo").val();
	$.ajax({
		type : "post",
		url : "${pageContext.request.contextPath}/Message/addNewMess",
		data : {
			titleName : titleName,
			titleInfo : titleInfo,
			author:"${userName}",
		},
		success:function(data) {
			if (data ==1) {
				alert("添加留言成功！");
				window.location.reload();
			}else{
				alert("添加留言失败！");
				window.location.reload();
			}
		},
		complete:function(xhr, status) {
			//拦截器拦截没有权限跳转
			// 通过xhr取得响应头
			var REDIRECT = xhr.getResponseHeader("REDIRECT");
			//如果响应头中包含 REDIRECT 则说明是拦截器返回的
			if (REDIRECT == "REDIRECT") {
				document.location.href = xhr
						.getResponseHeader("CONTEXTPATH");
			}
		}

	})
}
</script>
</head>
<body id="back">
	<!-- 头部区域 S-->
	<div>
		<header>
			<nav class="navbar navbar-inverse" role="navigation">
				<div class="container">
					<div class="navbar-header">
						<a class="navbar-brand" href="${pageContext.request.contextPath }/Message/allMess">卓捷电子留言系统</a>
					</div>
					<div class="row">
						<ul class="nav navbar-nav order">
							<li class="active"><a href="${pageContext.request.contextPath }/Message/allMess">首页</a></li>
							<li><a href="${pageContext.request.contextPath }/Message/toNewMess">新留言</a></li>
							<li><a href="#"
								style="${sessionScope.user==null?'':'display:none'}">注册</a></li>
							<li><a
								href="${pageContext.request.contextPath }/User/tologin"
								style="${sessionScope.user==null?'':'display:none'}">登录</a></li>
							<li class="dropdown"><a href="#" class="dropdown-toggle"
								style="${sessionScope.user==null?'display:none':''}"
								data-toggle="dropdown" role="button" aria-haspopup="true"
								aria-expanded="false">${userName}<span class="caret"></span></a>
								<ul class="dropdown-menu">
									<li><a
										href="${pageContext.request.contextPath }/User/exit">退出登录</a></li>
								</ul></li>
						</ul>
					</div>
				</div>
			</nav>
		</header>
		<!-- 头部区域 E-->
		<!-- 中部区域S -->
		<article id="body">
			<br>
			<center>
				<h3>发布新留言</h3>
			</center>

			<form role="form">
				<div class="form-group">
					<label for="titleName">标题</label> <input type="text"
						class="form-control" name="titleName" id="titleName"
						style="width: 700px" placeholder="请输入标题名称">
				</div>
				<div class="form-group">
					<label for="titleInfo">内容</label>
					<textarea type="text" class="form-control" name="titleInfo"
						id="titleInfo" cols="30" style="width: 700px" rows="10"></textarea>
				</div>
				<input type="button" class="form-group" value="提交"
					onclick="sendNewMess()">
			</form>
		</article>
		<!-- 中部区域E -->
	</div>
</body>
</html>